import {useRouter} from 'vue-router'
import { wholePaperBatchReview, saveCurrentCheck, getSingleQuestionReview } from '@/api/server/markPaper'
import { ref } from 'vue'

export default function useReview() {
  const router = useRouter()

  const allStudentPaperInfo = ref({})
  const studentPaperInfo = ref({})
  const currentQuestion = ref(null)

  // 整张试卷批阅
  const fetchReviewAssignmentList = async (data) => {
    const res = await wholePaperBatchReview(data)
    allStudentPaperInfo.value = res.data.data
    studentPaperInfo.value = allStudentPaperInfo.value.list[0]
    currentQuestion.value = studentPaperInfo.value.studentPaperDetail[0]

    finalScore.value = currentQuestion.value.finalScore ? currentQuestion.value.finalScore : 0
    teacherComment.value = currentQuestion.value.checkDetail ? currentQuestion.value.checkDetail : ''
  } 



  const goToTaskManage = () => {
    router.push({
      name: '评阅任务管理'
    })
  }


  // 小题得分
  const finalScore = ref(0)
  // 老师评语
  const teacherComment = ref('')



  // 保存当前批阅
  const saveCurrentCheckofHook = async (data) => {
   const res = await saveCurrentCheck(data)
   
   if(res.data.code === 200){
    ElMessage.success('保存成功')
   }else{
    ElMessage.error('保存失败')
   }
  }


const singleQuestionResult = ref({})
  // 进入单道大题批阅时调用
const getSingleQuestionReviewofHook = async (data) => {
    const res = await getSingleQuestionReview(data)
    singleQuestionResult.value = res.data.data
  }

  return {
    allStudentPaperInfo,
    studentPaperInfo,
    currentQuestion,
    finalScore,
    teacherComment,
    singleQuestionResult,

    goToTaskManage,
    fetchReviewAssignmentList,
    saveCurrentCheckofHook,
    getSingleQuestionReviewofHook
  }
}

